#include <iostream>
#include <log4cpp/Category.hh>
#include <log4cpp/Appender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/Layout.hh>
#include <log4cpp/BasicLayout.hh>
#include <log4cpp/Priority.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/RollingFileAppender.hh>
using namespace log4cpp;
using std::cout;
void test(){
    //设置日志布局
    PatternLayout *ptn1 = new PatternLayout();
    //布局指针和对应布局关联设置
    ptn1->setConversionPattern("%d %c [%p] %m%n");

    PatternLayout *ptn2 = new PatternLayout();
    ptn2->setConversionPattern("%d %c [%p] %m%n");

    PatternLayout *ptn3 = new PatternLayout();
    ptn3->setConversionPattern("%d %c [%p] %m%n");
    //设置 目的 包括 是终端还是文件
    //第二个参数是输出的地方 第一个是 自己设置的名字
    OstreamAppender *pos = new OstreamAppender("first",&cout);
    pos->setLayout(ptn1);

    FileAppender *fpos = new FileAppender("first","log1.txt");
    fpos->setLayout(ptn2);
    //设置回卷
    RollingFileAppender *rfPos = new RollingFileAppender("rollingfill"
                                                         ,"rollingfill.log"
                                                         ,5*1024
                                                         ,9);
    rfPos->setLayout(ptn3);

    //设置入职记录器对象 一般对象名和传入的 字符是一样的
    Category &salesDepart = Category::getInstance("salesDepart");

    //设置优先级
    salesDepart.setPriority(Priority::ERROR);

    //此时布局设置好了也和目的地关联好了 记录器需要和目的地关联
    salesDepart.addAppender(pos);
    salesDepart.addAppender(fpos);
    salesDepart.addAppender(rfPos);
    int cnt = 100;
    while(cnt--){
        //写入
        //使用记录器去调用
        salesDepart.emerg("is emerg");
        salesDepart.fatal("is fatal");
        salesDepart.alert("is alert");
        salesDepart.crit("is crit");
        salesDepart.error("is error");
        salesDepart.warn("is warn");
        salesDepart.notice("is notice");
        salesDepart.info("is info");
        salesDepart.debug("is debug");
//        salesDepart.notset("is notset");

    }
    salesDepart.shutdown();

}

int main()
{
    test();
    std::cout << "Hello world" << std::endl;
    return 0;
}

